<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Controller;


/**
 * Description of Index
 *
 * @author Administrator
 */
class ControllerMemcache{
	
	public function ActionIndex(){
		$memcache = new \Memcache();
		$memcache->connect('192.168.56.103', 11211);
		var_dump($memcache->getversion());
		var_dump($memcache->getstats());
		$memcache->close();
	}
	
	public function ActionAdd(){
		$memcache = new \Memcache();
		$memcache->connect('192.168.56.103', 11211);
		$memcache->add("key1", "val1", false, 30);
		$memcache->add("key1", "val2", false, 30);  //不会生效
		$memcache->add("key2", "val2", false, 30);
		var_dump($memcache->get("key1"));
		var_dump($memcache->get("key2"));
		var_dump($memcache->get("key3"));
		$memcache->close();
	}
	
	public function ActionGet(){
		$memcache = new \Memcache();
		$memcache->connect('192.168.56.103', 11211);
		$memcache->add("key1", "val1", false, 30);
		$memcache->add("key1", "val2", false, 30);  //不会生效
		$memcache->add("key2", "val2", false, 30);
		var_dump($memcache->get("key1"));
		var_dump($memcache->get("key2"));
		var_dump($memcache->get("key3"));
		$memcache->close();
	}
	
	public function ActionReplace(){
		$memcache = new \Memcache();
		$memcache->connect('192.168.56.103', 11211);
		$memcache->add("key1", "val1", false, 30);
		$memcache->replace("key1", "val11", false, 30);  //会生效
		$memcache->add("key1", "val2", false, 30);  //不会生效
		$memcache->add("key2", "val2", false, 30);
		var_dump($memcache->get("key1"));
		var_dump($memcache->get("key2"));
		var_dump($memcache->get("key3"));
		$memcache->close();
	}
	
	public function ActionSet(){
		$memcache = new \Memcache();
		$memcache->connect('192.168.56.103', 11211);
		$memcache->set("key1", "val1", false, 30);
		$memcache->set("key1", "val11", false, 30);  //会生效
		$memcache->set("key2", "val2", false, 30);
		var_dump($memcache->get("key1"));
		var_dump($memcache->get("key2"));
		var_dump($memcache->get("key3"));
		$memcache->close();
	}
	
	public function ActionDelete(){
		$memcache = new \Memcache();
		$memcache->connect('192.168.56.103', 11211);
		$memcache->set("key1", "val1", false, 30);
		$memcache->set("key2", "val1", false, 30);
		$memcache->set("key2", "val22", false, 30);  //会生效
		var_dump($memcache->get("key1"));
		$memcache->delete("key1");
		var_dump($memcache->get("key1"));
		$memcache->close();
	}
	
	public function ActionFlush(){
		$memcache = new \Memcache();
		$memcache->connect('192.168.56.103', 11211);
		//$memcache->set("key2", "val22", 0, 600000);  //会生效
		var_dump($memcache->get("key2"));
		$memcache->flush();
		var_dump($memcache->get("key2"));
		$memcache->set("key2", "val22", 0, 600000);  //会生效
		$memcache->close();
	}
}
